/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShEquipmentDevTalkDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShEquipmentDevTalkService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShEquipmentDevTalk;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShEquipmentDevTalkService 实现类
 * 
 * @author KongXiangyu
 * @since 2015-11-23
 */
@Service("shEquipmentDevTalkService")
public class ShEquipmentDevTalkServiceImpl extends BaseServiceImpl<ShEquipmentDevTalk, Long> implements ShEquipmentDevTalkService {

    @Resource
    private ShEquipmentDevTalkDao shEquipmentDevTalkDao;

    public BaseDao<ShEquipmentDevTalk, Long> getDao() {
        return shEquipmentDevTalkDao;
    }

    @Override
    public DataGrid queryDataGrid(ShEquipmentDevTalk devTalk, PageHelper page) {
        DataGrid dataGrid = new DataGrid();
        long totalCount = shEquipmentDevTalkDao.selectEntryListCount(devTalk);
        if (!StringUtils.isBlank(page.getOrder())) {
            devTalk.setOrderFieldType(page.getOrder());
        }
        if (!StringUtils.isBlank(page.getSort())) {
            devTalk.setOrderField(page.getSort());
        }
        dataGrid.setTotal(totalCount);
        int startIndex = (page.getPage() - 1) * page.getRows();
        int endIndex = page.getPage() * page.getRows();
        if (totalCount > 0 && totalCount > startIndex) {
            devTalk.setStartIndex(startIndex);
            devTalk.setEndIndex(endIndex);
            List<ShEquipmentDevTalk> ipcs = shEquipmentDevTalkDao.selectList(devTalk);
            dataGrid.setRows(ipcs);
        }
        return dataGrid;
    }

    @Override
    public ShEquipmentDevTalk selectById(ShEquipmentDevTalk devTalk) {
        return shEquipmentDevTalkDao.selectById(devTalk);
    }

    @Override
    public List<ShEquipmentDevTalk> getByBuildingIds(Long... buildingIds) {
        return shEquipmentDevTalkDao.getByBuildingIds(buildingIds);
    }

    @Override
    public void updateByResidenceId(ShEquipmentDevTalk shEquipmentDevTalk) {
        shEquipmentDevTalkDao.updateByResidenceId(shEquipmentDevTalk);
    }
}
